package com.eduhzy.ttw.work.mvp.ui.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.eduhzy.ttw.commonres.utils.RxUtil;
import com.eduhzy.ttw.commonsdk.core.Constants;
import com.eduhzy.ttw.commonsdk.core.RouterHub;
import com.eduhzy.ttw.commonsdk.decoration.GridSpacingItemDecoration;
import com.eduhzy.ttw.commonsdk.holder.AutoBaseViewHolder;
import com.eduhzy.ttw.work.R;
import com.eduhzy.ttw.work.R2;
import com.eduhzy.ttw.work.di.component.DaggerWorkUnreadComponent;
import com.eduhzy.ttw.work.di.module.WorkUnreadModule;
import com.eduhzy.ttw.work.mvp.contract.WorkUnreadContract;
import com.eduhzy.ttw.work.mvp.model.entity.WorkClassData;
import com.eduhzy.ttw.work.mvp.model.entity.WorkDetailData;
import com.eduhzy.ttw.work.mvp.presenter.WorkUnreadPresenter;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;
import com.qmuiteam.qmui.widget.QMUIEmptyView;
import com.qmuiteam.qmui.widget.dialog.QMUITipDialog;
import com.umeng.analytics.MobclickAgent;

import javax.inject.Inject;

import butterknife.BindView;

import static com.jess.arms.utils.Preconditions.checkNotNull;

/**
 * @author xubo
 * @date 2018-12-3 16:00:16
 */
@Route(path = RouterHub.WORK_WORKUNREADACTIVITY)
public class WorkUnreadActivity extends BaseActivity<WorkUnreadPresenter> implements WorkUnreadContract.View {
    @Autowired(name = Constants.ROUTER_INTEGER)
    int workId;
    @Autowired(name = Constants.PARCELABLE_DATA)
    WorkDetailData.HomeworkClassListBean mBean;
    @BindView(R2.id.tv_name)
    TextView mTvName;
    @BindView(R2.id.rv_list)
    RecyclerView mRvList;
    @BindView(R2.id.emptyView)
    QMUIEmptyView mEmptyView;
    @Inject
    BaseQuickAdapter<WorkClassData,AutoBaseViewHolder>mAdapter;
    @Inject
    RecyclerView.LayoutManager mLayoutManager;

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        //如找不到该类,请编译一下项目
        DaggerWorkUnreadComponent
                .builder()
                .appComponent(appComponent)
                .workUnreadModule(new WorkUnreadModule(this))
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        MobclickAgent.onEvent(getActivity(),"ttw_work_unread");
        //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
        return R.layout.work_activity_work_unread;
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        mTvName.setText(mBean.getClassName());
        showLoading();
        mPresenter.workRecordList4Teacher(workId, mBean.getClassId());
        mRvList.setAdapter(mAdapter);
        mRvList.setLayoutManager(mLayoutManager);
        GridSpacingItemDecoration decoration = new GridSpacingItemDecoration(4, RxUtil.getAutoHeight(this, 30), true);
        mRvList.addItemDecoration(decoration);
    }

    @Override
    public void showLoading() {
        mEmptyView.show(true);
    }

    @Override
    public void hideLoading() {
        mEmptyView.hide();
    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        RxUtil.showTipDialog(getActivity(), QMUITipDialog.Builder.ICON_TYPE_NOTHING, message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }

    @Override
    public Activity getActivity() {
        return this;
    }

}
